package com.xyht.sca_s.student_manage_system.modules.tips.controller;


import com.xyht.sca_s.student_manage_system.auth.util.JwtTokenUtil;
import com.xyht.sca_s.student_manage_system.common.annotation.RepeatRequestCheck;
import com.xyht.sca_s.student_manage_system.common.commonReturn.ResponseResult;
import com.xyht.sca_s.student_manage_system.common.desEncodeAndDecode.annotation.SecretBody;
import com.xyht.sca_s.student_manage_system.modules.tips.entity.req.SmsTipsRecordReq;
import com.xyht.sca_s.student_manage_system.modules.tips.service.SmsTipsService;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

import static com.xyht.sca_s.student_manage_system.auth.constant.CommonConstant.CLIENT_HEADER;

/**
 * <p>
 * 消息通知与待办 前端控制器
 * </p>
 *
 * @author XYHT
 * @since 2023-02-05
 */
@RestController
@RequestMapping("/tips")
@SecretBody
public class SmsTipsController {
    @Autowired
    private SmsTipsService smsTipsService;
    @Autowired
    private JwtTokenUtil jwtTokenUtil;


    @ApiModelProperty(value = "主页消息通知待办获取")
    @GetMapping("/list")
    public ResponseResult getTipsList(HttpServletRequest request,
                                              @RequestParam(value = "app_type",required = false) String app_type,
                                              @RequestParam(value = "type",required = false) Integer type,
                                              @RequestParam(value = "is_done",required = false) Integer is_done,
                                              @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                              @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {
        String user_id = jwtTokenUtil.getUserIdByRequest(request);
        Integer client = Integer.valueOf(request.getHeader(CLIENT_HEADER));
        return smsTipsService.getTipsList(user_id,type,is_done,pageNum,pageSize,client,app_type);
    }

    @ApiModelProperty(value = "应用列表")
    @GetMapping("/appList")
    public ResponseResult getAppTips(HttpServletRequest request,@RequestParam(value = "type",required = false) Integer type) {
        String user_id = jwtTokenUtil.getUserIdByRequest(request);
        Integer client = Integer.valueOf(request.getHeader(CLIENT_HEADER));
        return smsTipsService.getAppTips(user_id,client,type);
    }

    @ApiModelProperty(value = "通知小红点")
    @GetMapping("/getRedPoint")
    public ResponseResult getRedPoint(HttpServletRequest request,@RequestParam(value = "app_type",required = false) String type) {
        String user_id = jwtTokenUtil.getUserIdByRequest(request);
        Integer client = Integer.valueOf(request.getHeader(CLIENT_HEADER));
        return smsTipsService.getRedPoint(user_id,client,type);
    }

    @ApiModelProperty(value = "消息已读")
    @PostMapping("/read")
    @RepeatRequestCheck(name = "tipsRead")
    public ResponseResult tipsRead(@RequestBody SmsTipsRecordReq tipsRecordReq,HttpServletRequest request) {
        String user_id = jwtTokenUtil.getUserIdByRequest(request);
        return smsTipsService.tipsRead(tipsRecordReq,user_id);
    }

}

